package com.example.woke1;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebSettings.TextSize;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.http.HttpMethods;
import com.zhongcai.online.R;

//import com.example.woke.HtmlActivity.JavascriptInterface;

public class ZhcaidinginfoActivity extends Activity {

	private String id;
	private WebView mWebView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_zhcaidinginfo);
		
		intview();
		
	}

	private void intview() {
		
		id = getIntent().getStringExtra("id");
		
		findViewById(R.id.zhcaidinginfo_image_back).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		mWebView = (WebView) findViewById(R.id.webView13);
		WebSettings settings = mWebView.getSettings();
		setSettings(settings);
		
//		mWebView.addJavascriptInterface(new JavascriptInterface(
//				getApplicationContext()), "imagelistner");
		mWebView.setWebChromeClient(new MyWebChromeClient());
		mWebView.setWebViewClient(new MyWebViewClient());
//		mWebView.loadUrl("http://www.88china.com");
		mWebView.loadUrl(HttpMethods.BASEURL+"g=api&m=financial&a=hkbz&id="+id);
	}
		
		
		private void setSettings(WebSettings settings) {
			settings.setJavaScriptEnabled(true);// ���ÿ�������JS�ű�
			settings.setDefaultTextEncodingName("UTF-8");
			settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
			mWebView.setBackgroundColor(getResources().getColor(R.color.white)); // ���ñ���ɫ  
//			mWebView.getBackground().setAlpha(50); // �������͸���� ��Χ��0-255 
			settings.setSupportZoom(false);// ��������webview�Ŵ�
			settings.setBuiltInZoomControls(false);
			settings.setDomStorageEnabled(true);
			settings.setTextSize(TextSize.NORMAL);
//			settings.setPluginState(PluginState.ON);
			settings.setDatabaseEnabled(true);
		}

		// jsͨ�Žӿ�
		public class JavascriptInterface {

			private Context context;
			Intent intent = new Intent();

			public JavascriptInterface(Context context) {
				this.context = context;
			}
			public void thisImage(String index){
				intent.putExtra("index", index);
			}
		}
		// ����
		private class MyWebViewClient extends WebViewClient {
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				if (url != null) {
					Uri uri = Uri.parse(url);  
	                Intent intent = new Intent(Intent.ACTION_VIEW, uri);  
	                startActivity(intent);  
					  
//					finish();
					return true;
					}
//				return false;
				
				return super.shouldOverrideUrlLoading(view, url);
			}
			@Override
			public void onPageFinished(WebView view, String url) {
				view.getSettings().setJavaScriptEnabled(true);
				mWebView.setVisibility(View.VISIBLE);
				super.onPageFinished(view, url);
			}

			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				view.getSettings().setJavaScriptEnabled(true);
				super.onPageStarted(view, url, favicon);
			}

			@Override
			public void onReceivedError(WebView view, int errorCode,
					String description, String failingUrl) {
				super.onReceivedError(null, 1, "访问失败", null);
			}
		}

		private class MyWebChromeClient extends WebChromeClient {
			@Override
			public void onProgressChanged(WebView view, int newProgress) {
				super.onProgressChanged(view, newProgress);
			}
			
			@Override
			public void onReceivedTitle(WebView view, String title) {
				super.onReceivedTitle(view, title);
			}
			
			@Override
			public void onReceivedTouchIconUrl(WebView view, String url,
					boolean precomposed) {
				super.onReceivedTouchIconUrl(view, url, precomposed);
			}
		}
		
	}
